#include<iostream>
#include<fstream>
#include"contacts.pb.h"
using namespace std;
using namespace google::protobuf;
void PrintContact(c_contacts::Contacts&contacts)
{
    for(int i=0;i<contacts.contacts_size();i++)
    {
        cout<<"-------------联系人"<<i+1<<"---------------"<<endl;
        const c_contacts::PeopleInfo&people=contacts.contacts(i);
        cout<<"联系人姓名: "<<people.name()<<endl;
        cout<<"联系人年龄: "<<people.age()<<endl;
        const Reflection *reflection=c_contacts::PeopleInfo::GetReflection();
        const UnknownFieldSet&set=reflection->GetUnknownFields(people);
        for(int j=0;j<set.field_count();j++)
        {
            const UnknownField&unknown_field=set.field(j);
            cout<<"未知字段"<<j+1<<": "<<"编号"<<unknown_field.number();
            switch(unknown_field.type())
            {
                case UnknownField::Type::TYPE_VARINT:
                cout<<" 值："<<unknown_field.varint()<<endl;
                break;
                case UnknownField::Type::TYPE_LENGTH_DELIMITED:
                cout<<" 值："<<unknown_field.length_delimited()<<endl;
                break;
            }
        }

    }
}
int main() 
{
    c_contacts::Contacts contacts;
    fstream input("1.bin",ios::in | ios::binary);
    if(!input)
    {
        cout<<"1.bin not find,create new file"<<endl;
    }
    else if(!contacts.ParseFromIstream(&input))
    {
        cerr<<"parse error!"<<endl;
        input.close();
        return -1;
    }
    PrintContact(contacts);
    return 0;
}